import request from '@/utils/request';

// 分页获取系统密码
export function getSysPwdPage(currentPage, pageSize, searchParam) {
  return request({
    url: '/v1/sys/accounts/page',
    method: 'get',
    params: {
      currentPage,
      pageSize,
      name: searchParam.name === '' ? null : searchParam.name,
      accountTypeId: searchParam.accountTypeId === '' ? null : searchParam.accountTypeId
    }
  });
}
// 增加一个系统密码
export function addSysPwd(pwd) {
  return request({
    url: '/v1/sys/accounts',
    method: 'post',
    data: pwd
  });
}
// 修改系统账户
export function updateSysPwd(id, pwd) {
  return request(
    {
      url: '/v1/sys/accounts/' + id,
      method: 'put',
      data: {
        'id': id,
        'account': pwd.account,
        'accountTypeId': pwd.accountTypeId,
        'name': pwd.name,
        'password': pwd.password,
        'remark': pwd.remark,
        'url': pwd.url
      }
    }
  );
}

// 删除系统账户
export function deleteSysPwd(id) {
  return request({
    url: '/v1/sys/accounts/' + id,
    method: 'delete'
  });
}

// 获取所有系统类型
export function getSysType() {
  return request({
    url: '/v1/sys/account-types',
    method: 'get'
  });
}

export function addSysType(name, remark) {
  return request({
    url: '/v1/sys/account-types',
    method: 'post',
    data: { name, remark }
  });
}

export function updateSysType(id, name, remark) {
  return request({
    url: '/v1/sys/account-types/' + id,
    method: 'put',
    data: {
      id,
      name: name === '' ? null : name,
      remark: remark === '' ? null : remark
    }
  });
}

export function deleteSysType(id) {
  return request({
    url: '/v1/sys/account-types/' + id,
    method: 'delete'
  });
}
